<template>
	<view class="contaier">
		<view class="top-bg">
			<view class="text-white text-bold text-xxxl">无人自助</view>
			<view class="margin-top-xs text-white">欢迎使用，请先登录</view>
		</view>

		<view class="input-box padding-lr">
			<form>
				<view class="cu-form-group margin-top">
					<view class="title">手机号</view>
					<input placeholder="两字短标题" name="input"  v-model="phoneCode"></input>
				</view>

				<view class="cu-form-group solid-bottom">
					<view class="title">验证码</view>
					<input placeholder="输入框带个按钮" name="input"  v-model="phoneCode"></input>
					<button class='cu-btn bg-login-zl shadow'>验证码</button>
						<!-- <button class='cu-btn bg-login-zl shadow'>{{test}}</button> -->
				</view>
			</form>
		</view>
	<view class="padding margin-top-xs"> 
			<button class="cu-btn block round bg-login-zl margin-tb-sm lg" @click="phone()">立即登录</button>
		<!-- 	<view class="text-gray flex justify-between padding-lr-sm">
				<text>注册账号</text>
				<text>忘记密码</text>
			</view> -->
		</view>

	</view>
</template>

<script>
	// pages/login/login.js
	var http = require('../../utils/http');
	var util1 = require('../../utils/util.js');
	const app = getApp();
	window.onload = () => {
		var btn = document.getElementsByClassName("shadow")[0]; //获取验证码按钮
		// 注册单击事件
		btn.addEventListener('click', function() {
			console.log("555");
			var time = 59;
			// 禁用按钮
			btn.disabled = true;
			// 开启定时器
			var timer = setInterval(function() {
				// 判断剩余秒数
				if (time == 0) {
					// 清除定时器和复原按钮
					clearInterval(timer);
					btn.disabled = false;
					btn.innerHTML = '发送验证码';
				} else {
					btn.innerHTML = `${time}秒后重新获取`;
					time--;
				}
			}, 1000);
		});
	}
	export default {
		data() {
			return {
				code: "",
				test:"",
				phoneCode:"",
				appName: app.globalData.appName,
				isLogin: false,
				statusBarHeight: "",
				statusBarHeight: "",
				userinfo: {
					avatar: false
				}
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad(options) {
			let that = this;

			that.statusBarHeight = uni.getStorageSync('statusBarHeight')
			that.titleBarHeight = uni.getStorageSync('titleBarHeight')


		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {},
		mounted() {
			const urlParams = new URLSearchParams(window.location.search);
			this.code = urlParams.get('code');
			if (this.code) {
				return
			}
			const url = 'http://172.168.1.23:8080/pages/login/login'
			// const url = 'http://172.168.1.37:8848/ysbhou/page/table-select.html'
				window.location.href = `http://ceshicode.yes-pay.cn?huidiao=${url}`
		},
		methods: {
			phone(){
				// this.phoneCode=0
				var that=this
				http.request(
						'/member/auth/weixin-mini-app-login',
						'1',
						'post', {
							phoneCode: that.phoneCode,
							loginCode:that.code
						},
						'',
						'获取中...',
						function success(info) {
							console.info('返回111===');
							console.info(info);
							if (info.code == 0) {
								if (info.data) {
									app.globalData.userDatatoken = info.data;
									app.globalData.isLogin = true;
									that.setData({
										isLogin: true
									});
									//缓存服务器返回的用户信息
									uni.setStorageSync('userDatatoken', info.data);
									uni.showToast({
										title: '登录成功',
										icon: 'none'
									});
									setTimeout(function() {
									uni.switchTab({
														url: '/pages/user/user'
													})
									}, 1000);
								}
							}
						},
						function fail(info) {}
					);
				
		
			}
		
		
		
		// 	phone: function(e) {
		// 		console.log('授权用户手机号');
		// 		var that = this;
		// 		if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
		// 			uni.showToast({
		// 				title: '已取消授权'
		// 			});
		// 		}
		// 		if (e.detail.errMsg == 'getPhoneNumber:ok') {
		// 			//console.log('手机号码授权+++++++');
		// 			//console.log(e.detail);
		// 			//console.log('手机号码授权+++++++');
		// 			uni.login({
		// 				success: function(res) {
		// 					//console.log('111++++==');
		// 					//console.log(res);
		// 					//console.log('111++++==');
		// 					if (res.code != null) {
		// 						http.request(
		// 							'/member/auth/weixin-mini-app-login',
		// 							'1',
		// 							'post', {
		// 								phoneCode: e.detail.code,
		// 								loginCode: res.code
		// 							},
		// 							'',
		// 							'获取中...',
		// 							function success(info) {
		// 								console.info('返回111===');
		// 								console.info(info);
		// 								if (info.code == 0) {
		// 									if (info.data) {
		// 										app.globalData.userDatatoken = info.data;
		// 										app.globalData.isLogin = true;
		// 										that.setData({
		// 											isLogin: true
		// 										});
		// 										//缓存服务器返回的用户信息
		// 										uni.setStorageSync('userDatatoken', info.data);
		// 										uni.showToast({
		// 											title: '登录成功',
		// 											icon: 'none'
		// 										});
		// 										setTimeout(function() {
		// 											uni.navigateBack({
		// 												delta: 1
		// 											});
		// 										}, 2000);
		// 									}
		// 								}
		// 							},
		// 							function fail(info) {}
		// 						);
		// 					} else {
		// 						console.log('登录失败！' + res.errMsg);
		// 					}
		// 				}
		// 			});
		// 		} else {
		// 			console.log(e.detail.errMsg);
		// 		}
		// 	}
		
		
		
		
		}
	};
</script>
<style lang="scss" scoped>
	.contaier {

		background-color: #ffffff;
	}

	.top-bg {
		width: 750rpx;
		background-image: url(https://cdn.zhoukaiwen.com/head-bg.png);
		height: 480rpx;
		background-size: 100%;
		background-repeat: no-repeat;
		text-align: center;
		padding-top: 170rpx;
	}

	.bg-login-zl {
		background-image: linear-gradient(45deg, #727CFB, #46D0ED);
		color: #ffffff;
	}
</style>